/**
 * Created by cuppi on 2017/7/19.
 */

import {JNetwork} from 'jbzwebsdk';
import QiNiuManager from '../util/QiNiuManager';
// import StringTool from '../tool/StringTool'

class NetworkManager{
  static GetTokenError = -801;
  static UploadImageError = -802;

  static uploadWithBase64Image(key, base64){
    return new Promise((resolve, reject) => {
      JNetwork.POST('token').then(accessToken => {
        QiNiuManager.defaultManager().uploadImage(accessToken, key, base64).then(imageUrl => {
          JNetwork.POST('register', {userId: key, userGroup: 'test', userFaceUrl:imageUrl}).then(data => {
            resolve({data, userFaceUrl:imageUrl});
          })
        }, error => {
          reject(this.networkError(-802, error.message));
        });
      }, error => {
        reject(this.networkError(-801, error.message));
      });
    });
  }

  static networkError(code, message){
    let error = new Error('message');
    error.errorCode = code;
    return error;
  }
}

export default NetworkManager;
